# Makefile.am


bin_PROGRAMS=$(TARGET)

TARGET=jattbak

jattbak_SOURCES=$(SRC)

SRC=\
	main.c \
	base_dlist.h base_dlist.c \
	base_dlist_test.h base_dlist_test.c \
	timer.h timer.c \
	base_test.h base_test.c \
	unittests.c



if AVR8_BUILD
AM_CFLAGS= \
	-mmcu=@MCU@ \
	-g \
	-Os \
	-funsigned-char \
	-funsigned-bitfields \
	-fpack-struct \
	-fshort-enums \
	-Wall \
	-Wstrict-prototypes \
	-ffunction-sections
#	-ahlms=$(<:.c=.lst)
endif

AM_LDFLAGS=-Wl,-Map=$(TARGET).map,-gc-sections, --cref
#AM_LDFLAGS+=-Wl,-gc-sections

if AVR8_BUILD
FORMAT=ihex

$(TARGET).hex: $(TARGET)
	$(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@

$(TARGET).eep: $(TARGET)
	-$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
	--change-section-lma .eeprom=0 -O $(FORMAT) $< $@

$(TARGET).lss: $(TARGET)
	$(OBJDUMP) -h -S $< > $@

size: $(TARGET)
	$(SIZE) -B $<

all: $(TARGET).hex $(TARGET).eep $(TARGET).lss size
endif



check_PROGRAMS=unittests

unittests_SOURCES=unittests.c \
	base_test.h base_test.c \
	base_dlist_test.h base_dlist_test.c

unittests_CFLAGS=-DTEST_MAIN
unittests_LDFLAGS=\
	base_dlist.o

TESTS=$(check_PROGRAMS)

